﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Core.Entity;
using Core.Dao;
using System.Data;

namespace Core.Business
{
    public class TicketStatusBus
    {
        private TicketStatusDao dao;
        public TicketStatusBus() {
            dao = new TicketStatusDao();
        }

        public bool insert(TicketStatus ticketStatus) {
            return dao.insert(ticketStatus);
        }

        public bool update(TicketStatus ticketStatus) {
            return dao.update(ticketStatus);
        }

        public bool delete(int id) {
            return dao.delete(id);
        }

        public bool delete(String ids) {
            return dao.delete(ids);
        }

        public TicketStatus get(int id) {
            DataTable dt = dao.get(id);
            TicketStatus ticketStatus = new TicketStatus();

            if (dt.Rows.Count > 0)
            {
                ticketStatus.Id = Convert.ToInt32(dt.Rows[0]["TKS_ID"]);
                ticketStatus.Name = dt.Rows[0]["TKS_NAME"].ToString();
                ticketStatus.Desc = dt.Rows[0]["TKS_DESC"].ToString();
            }
            return ticketStatus;
        }

        public List<TicketStatus> getAll() {
            DataTable dt = dao.getAll();
            List<TicketStatus> list = new List<TicketStatus>();

            if (dt.Rows.Count > 0)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    TicketStatus ticketStatus = new TicketStatus();
                    ticketStatus.Id = Convert.ToInt32(dr["TKS_ID"]);
                    ticketStatus.Name = dr["TKS_NAME"].ToString();
                    ticketStatus.Desc = dr["TKS_DESC"].ToString();

                    list.Add(ticketStatus);
                }

            }
            return list;
        }
    }
}
